import * as dayjs from "dayjs";
// 拼接路径
export const chckGetParams = function(obj) {
    let str = "?";
    Object.keys(obj).forEach((ele, index) => {
      if (index == 0) {
        str += ele + "=" + obj[ele];
      } else {
        if (index <= Object.keys(obj).length - 1) {
          str += "&" + ele + "=" + obj[ele];
        }
      }
    });
    return str;
  }

export const getCouponeTip = function(data) {
  if(data) {
		let code = {
			0:"满"+data.fullMoney+getCouponUnit(data)+"减"+data.subtractMoney,
			1:data.noThresholdMoney+"元无门槛",
			2:data.discount+"折券"
		}
		return code[data.couponType]
	}
	return null
}

export const getCouponUnit = function({fullUnit,couponType}) {
  if(couponType == 0) {
		let code = {
			0:"元",
			1:"件"
		}
		return code[fullUnit]
	}
}

export const getStarTimeRange = function(type = 0) {
  let startTime = dayjs().subtract(type ==1?30:type ==2?41:0, "day").format("YYYY-MM-DD") + " 00:00:00",
    endTime = dayjs().format("YYYY-MM-DD") + " 23:59:59";
  return {
    startTime: type == 1 ? "2023-01-01 00:00:00" : startTime,
    endTime,
  };
}